
/*_________________________________________点击查询按钮_____________________________________________*/	
	
	$(".querySpan").click(function(){
		$(".page").val("1")
		getAjax()
	})


/*_________________________________________点击航班号进入详情页面___________________________________*/	
	$("table").delegate(".airlineCode","click",function(){
		 var airlineCode=$(this).text();//获取航班号
		 var departureDate=$(this).parent().find("span[class=depDate]").text();//获取出发日期 
		 var depCn=$(this).parent().find("span[class=depCn]").text();//获取出去机场名称
		 var dep=$(this).parent().find("span[class=depAirport]").text();//获取出去机场三字码
		 var arrCn=$(this).parent().find("span[class=arrCn]").text();//获取到达机场名称
		 var arr=$(this).parent().find("span[class=arrAirport]").text();//获取到达机场三字码
	
		layer.open({
			type: 2,
			title: ['航线销售详情','background-color:#6d6e72; color:#fff;font-size:14px;'],
			shadeClose: true,
			shade: [0.9,'#cfcfcf'],
			area: ['98%', '98%'],  
			content: ['../ak/flightSaleDetail.html?airlineCode='+airlineCode+"&departureDate="+departureDate+"&depCn="+encodeURI(depCn)+"&dep="+dep+"&arrCn="+encodeURI(arrCn)+"&arr="+arr],  // iframe的url，no代表不显示滚动条
			end:function(){
			//	getAjax();
			}	
		});
		
	})
		
	
	
/*_______________________________________封装ajax请求函数_____________________________________________*/		
	function getAjax(){
		var airlineCode1 = ($(".airlineCode1").val()).toUpperCase();
		var airlineCode2 = ($(".airlineCode2").val()).toUpperCase();
		var startDate = $(".startDate").val();
		var endDate = $(".endDate").val();
		if(airlineCode1==""||startDate==""||endDate==""){
			layer.msg("请输入完整的查询信息",{icon:2,time:1000})
			return false;
		}
		$.ajax({
			type:"get",
			url:"../statistics/subProductCompositeList?airlineCode1="+airlineCode1+"&airlineCode2="+airlineCode2+"&startDate="+startDate+"&endDate="+endDate+"&temp="+Math.random(),
			dataType:"json",
			success:function(data){
			
				//每次经行请求时清空页面原有数据
				$(".clear").empty()	
				if(data.data.length==0){
					layer.msg("没有搜索到结果");
					return false;
				}
				var str="";		
				for(var i=0;i<data.data.length;i++){
					
					var length = Object.keys(data.data[i].subProductList).length;//获取一个产品的长度
					var index = 0;
					for(var pro_attr in data.data[i].subProductList){
						//console.log(data.data[i].subProductList[pro_attr]);
						index++;
					
							str+="<tr>"
						
						 	str+="<td class='flightNumId'><span class='airlineCode faa000'>"+data.data[i].subProductList[pro_attr].airlineCode+"</span><span class=depDate style=display:none>"+data.data[i].subProductList[pro_attr].depDate+"</span>" +
						 			"<span class=depCn style=display:none>"+data.data[i].subProductList[pro_attr].depCn+"</span>"+
						 			"<span class=depAirport style=display:none>"+data.data[i].subProductList[pro_attr].depAirport+"</span>"+
						 			"<span class=arrCn style=display:none>"+data.data[i].subProductList[pro_attr].arrCn+"</span>"+
						 			"<span class=arrAirport style=display:none>"+data.data[i].subProductList[pro_attr].arrAirport+"</span>"+
						 		 "</td>" +	
						 	
						 	"<td><span class='font14px f262929'>"+data.data[i].subProductList[pro_attr].depCn+"&nbsp;(&nbsp;"+data.data[i].subProductList[pro_attr].depAirport+"&nbsp;)&nbsp;</span></br><span class='depDate_color f00aa99'>"+data.data[i].subProductList[pro_attr].depDate+"</span>&nbsp;&nbsp;<span>"+data.data[i].subProductList[pro_attr].depTime+"</span></td>"+
						 	"<td><span class='font14px f262929'>"+data.data[i].subProductList[pro_attr].arrCn+"&nbsp;(&nbsp;"+data.data[i].subProductList[pro_attr].arrAirport+"&nbsp;)&nbsp;</span></br><span class='depDate_color f00aa99'>"+data.data[i].subProductList[pro_attr].arrDate+"</span>&nbsp;&nbsp;<span>"+data.data[i].subProductList[pro_attr].arrTime+"</span></td>"+
						 	"<td></td>"
						 	if(index==1){
						 		str+="<td class='font14px fa2828' rowspan="+length+">"+data.data[i].actualRevenue+"</td>" +	
							    "<td class='font14px f262929' rowspan="+length+">"+data.data[i].totalRevenue+"</td>" +	
							 	"<td class='font14px f00aa99' rowspan="+length+" class='depDate_color' >"+data.data[i].completionRate+"%</td>" 
							 	
						 	}
							str+="</tr>"
						 	
					}
				}
					
				$(".clear").append(str)
			}									
		});	
	}
//________________________________________表头固定____________________________________________
	$("#dataTable").freezeHeader();
/*___________________________________________分页______________________________________________*/
	 	//选择每页的条数
		$(".pageSize").change(function(){
			$('.page').val('1')
			getAjax()
	   })
	   //首页
		$(".indexPage").click(function(){
			var pageNum = $('.page').val('1');
			getAjax()
	   })
	   //上一页
		$(".prePage").click(function(){
			var pageNum = $('.page').val();	
			if(pageNum == 1){
				$('.page').val('1');
			}else{
				$('.page').val(pageNum-1);
			}
			getAjax()
	   })
	   //跳转到第几页	
			$('.page').keypress(function(){
				if(event.keyCode ==13){			
					if($('.page').val()<=totalPage){
						var pageNum = $('.page').val();
						getAjax()
					}else{
						var pageNum = $('.page').val(totalPage)
						getAjax()
					}					
				}
			})
	 
	   //下一页
		$(".nextPage").click(function(){
			var pageNum = $('.page').val();	
			if(pageNum == totalPage){
				$('.page').val(totalPage);
			}else{
				$('.page').val(pageNum-0+1);
			}			
			getAjax();
	   })
	   //尾页
		$(".lastPage").click(function(){
			var pageNum = $('.page').val(totalPage);
			getAjax();
	   })
	  
	
	
	
	
	